package com.umeng.analytics.pro;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

public class bz {
    private static List<WeakReference<ScheduledFuture<?>>> a;
    private static ExecutorService b;
    private static long c;
    private static ScheduledExecutorService d;

    static {
        bz.a = new ArrayList();
        bz.b = Executors.newSingleThreadExecutor();
        bz.c = 5;
        bz.d = Executors.newSingleThreadScheduledExecutor();
    }

    public bz() {

    }

    public static void a(Runnable runnable) {
        if (bz.b.isShutdown()) {
            bz.b = Executors.newSingleThreadExecutor();
        }

        bz.b.execute(runnable);
    }

    public static void a() {
        try {
            Iterator<WeakReference<ScheduledFuture<?>>> v1 = bz.a.iterator();
            while (v1.hasNext()) {
                Object v0_1 = v1.next().get();
                if (v0_1 == null) {
                    continue;
                }

                ((ScheduledFuture) v0_1).cancel(false);
            }

            bz.a.clear();
            if (!bz.b.isShutdown()) {
                bz.b.shutdown();
            }

            if (!bz.d.isShutdown()) {
                bz.d.shutdown();
            }

            bz.b.awaitTermination(bz.c, TimeUnit.SECONDS);
            bz.d.awaitTermination(bz.c, TimeUnit.SECONDS);
            return;
        } catch (Exception v0) {
        }
    }

    public static void a(Runnable arg5, long arg6) {
        Class v1 = bz.class;
        synchronized (v1) {
            if (bz.d.isShutdown()) {
                bz.d = Executors.newSingleThreadScheduledExecutor();
            }

            bz.a.add(new WeakReference(bz.d.schedule(arg5, arg6, TimeUnit.MILLISECONDS)));
        }
    }

    public static void b(Runnable runnable) {
        Class v1 = bz.class;
        synchronized (v1) {
            if (bz.d.isShutdown()) {
                bz.d = Executors.newSingleThreadScheduledExecutor();
            }
            bz.d.execute(runnable);
        }
    }

    public static void c(Runnable arg5) {
        Class v1 = bz.class;
        synchronized (v1) {
            if (bz.d.isShutdown()) {
                bz.d = Executors.newSingleThreadScheduledExecutor();
            }

            Future v0_1 = bz.d.submit(arg5);
            long v2 = 5;
            try {
                v0_1.get(v2, TimeUnit.SECONDS);
            } catch (Exception v0_2) {
            }
        }
    }
}

